<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Token测试和重定向</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            max-width: 800px;
            margin: 50px auto;
            padding: 20px;
            background-color: #f5f5f5;
        }
        .container {
            background: white;
            padding: 30px;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }
        button {
            background: #1890ff;
            color: white;
            border: none;
            padding: 10px 20px;
            margin: 10px;
            border-radius: 4px;
            cursor: pointer;
        }
        button:hover {
            background: #40a9ff;
        }
        .info {
            background: #f6ffed;
            border: 1px solid #b7eb8f;
            padding: 15px;
            margin: 15px 0;
            border-radius: 4px;
        }
        .error {
            background: #fff2f0;
            border: 1px solid #ffccc7;
            padding: 15px;
            margin: 15px 0;
            border-radius: 4px;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>Dashboard访问测试</h1>
        
        <div class="info">
            <h3>当前状态:</h3>
            <p>Token状态: <span id="tokenStatus">检查中...</span></p>
            <p>当前URL: <span id="currentUrl"></span></p>
            <p>时间: <span id="currentTime"></span></p>
        </div>
        
        <div>
            <button onclick="setTokenAndRedirect()">设置Token并跳转到Dashboard</button>
            <button onclick="clearTokenAndRedirect()">清除Token并跳转到Login</button>
            <button onclick="directToDashboard()">直接跳转到Dashboard</button>
            <button onclick="checkStatus()">刷新状态</button>
        </div>
        
        <div id="logs" class="info">
            <h3>操作日志:</h3>
            <div id="logContent"></div>
        </div>
    </div>

    <script>
        function log(message) {
            const logContent = document.getElementById('logContent');
            const time = new Date().toLocaleTimeString();
            logContent.innerHTML += `<p>[${time}] ${message}</p>`;
            console.log(message);
        }
        
        function updateStatus() {
            const token = localStorage.getItem('admin_token');
            document.getElementById('tokenStatus').textContent = token ? '已设置' : '未设置';
            document.getElementById('currentUrl').textContent = window.location.href;
            document.getElementById('currentTime').textContent = new Date().toLocaleString();
        }
        
        function setTokenAndRedirect() {
            log('设置测试token...');
            localStorage.setItem('admin_token', 'test-token-' + Date.now());
            updateStatus();
            log('Token已设置，3秒后跳转到Dashboard...');
            setTimeout(() => {
                log('跳转到Dashboard页面');
                window.location.href = '/dashboard';
            }, 3000);
        }
        
        function clearTokenAndRedirect() {
            log('清除token...');
            localStorage.removeItem('admin_token');
            updateStatus();
            log('Token已清除，3秒后跳转到Login...');
            setTimeout(() => {
                log('跳转到Login页面');
                window.location.href = '/login';
            }, 3000);
        }
        
        function directToDashboard() {
            log('直接跳转到Dashboard页面');
            window.location.href = '/dashboard';
        }
        
        function checkStatus() {
            updateStatus();
            log('状态已刷新');
        }
        
        // 页面加载时初始化
        window.onload = function() {
            updateStatus();
            log('页面加载完成');
        };
    </script>
</body>
</html>